package com.liuweiheng.cloud.component;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * Kafka消费者
 * @author lwh
 * @since 2021/8/23
 */
//@Component
public class KafkaConsumer {

    /**
     * 持续接收消息
     * @param record
     */
    @KafkaListener(topics = {"chat"}, groupId = "defaultConsumerGroup")
    public void onMessage(ConsumerRecord<?, ?> record) {
        // 消费的哪个topic、partition的消息,打印出消息内容
        System.out.println("简单消费：" + record.topic() + "-" + record.partition() + "-" + record.value());
    }

}
